#include <stdio.h>
#include <stdlib.h>

void copyFile(const char *filePath ,const char *destPath){
    FILE *fr=fopen(filePath,"r");
    if(!fr){
        printf("文件读取失败\n");
        return;
    }
    FILE *fw=fopen(destPath,"w");
    if(!fw){
        printf("文件写入失败\n");
        fclose(fr);
        return;
    }

    fseek(fr,0,SEEK_END);
    long size=ftell(fr);
    fseek(fr,0,SEEK_SET);


    char chunck[4096]={0};
    // if(!p){
    //     printf("申请内存失败");
    //     fclose(fr);
    //     fclose(fw);
    // }

    //分块传输
    long readSize=0;//已经读取了多少字节
    while(readSize!=size){
        long trueSize=size-readSize>4096?4096:size-readSize;
        printf("拷贝了%ld个字节\n",trueSize);
        fread(chunck,trueSize,1,fr);
        fwrite(chunck,trueSize,1,fw);
        readSize+=trueSize;
    }
    
    fclose(fr);
    fclose(fw);

}



int main(){
    copyFile("/home/lvguanzhong/qt-opensource-linux-x64-5.12.12.run","./qt.run");
    return 0;
}